package com.d3works.apps.talent.db.repo;

import com.d3works.apps.base.db.repo.SequenceRepository;
import com.d3works.apps.base.service.administration.SequenceService;
import com.d3works.apps.talent.db.JobPosition;
import com.d3works.exception.D3worksException;
import com.d3works.exception.service.TraceBackService;
import com.google.inject.Inject;

public class JobPositionTalentRepository extends JobPositionRepository {

  @Inject private SequenceService sequenceService;

  @Override
  public JobPosition save(JobPosition jobPosition) {

    if (jobPosition.getStatusSelect() > 0 && jobPosition.getJobReference() == null) {
      try {
        jobPosition.setJobReference(
            sequenceService.getSequenceNumber(
                SequenceRepository.JOB_POSITION, JobPosition.class, "jobReference"));
      } catch (D3worksException e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
      }
    }

    return super.save(jobPosition);
  }
}
